package cn.com.cetccst.onlinecert;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MdmUserInfo {
    private String userName;
    private String email;
    private String orgName;
    private String tenantName;
    private String account;
    private String imei;
    private String city;
    private String province;
    private String phone;

    public String getPhone() {
        return phone;
    }

    public MdmUserInfo setPhone(String phone) {
        this.phone = phone;
        return this;
    }

    public String getCity() {
        return city;
    }

    public MdmUserInfo setCity(String city) {
        this.city = city;
        return this;
    }

    public String getProvince() {
        return province;
    }

    public MdmUserInfo setProvince(String province) {
        this.province = province;
        return this;
    }

    public String getTenantName() {
        return tenantName;
    }

    public MdmUserInfo setTenantName(String tenantName) {
        this.tenantName = tenantName;
        return this;
    }

    public String getImei() {
        return imei;
    }

    public MdmUserInfo setImei(String imei) {
        this.imei = imei;
        return this;
    }

    public String getUserName() {
        return userName;
    }

    public MdmUserInfo setUserName(String userName) {
        this.userName = userName;
        return this;
    }

    public String getEmail() {
        return email;
    }

    public MdmUserInfo setEmail(String email) {
        this.email = email;
        return this;
    }

    public String getOrgName() {
        return orgName;
    }

    public MdmUserInfo setOrgName(String orgName) {
        this.orgName = "";
        try {
            JSONArray array = new JSONArray(orgName);
            if (array.length() > 0) {
                for (int i = 0; i < array.length(); ++i) {
                    JSONObject object = new JSONObject(array.get(i).toString());
                    this.orgName += object.optString("name");
                    if (i != array.length() - 1) {
                        this.orgName += " ";
                    }
                }
            } else {
                this.orgName = orgName.replace("[", "").replace("]", "");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return this;
    }

    public String getAccount() {
        return account;
    }

    public MdmUserInfo setAccount(String account) {
        this.account = account;
        return this;
    }

    @Override
    public String toString() {
        return "MdmUserInfo{" +
                "userName='" + userName + '\'' +
                ", email='" + email + '\'' +
                ", orgName='" + orgName + '\'' +
                ", tenantName='" + tenantName + '\'' +
                ", account='" + account + '\'' +
                ", imei='" + imei + '\'' +
                ", city='" + city + '\'' +
                ", province='" + province + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}
